package com.back.end.Controller;

import com.back.end.Modal.Order;
import com.back.end.Modal.RefundOrder;
import com.back.end.Service.OrdersService;
import com.back.end.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrdersController {

    @Resource
    OrdersService ordersService;

    @PostMapping("/createOrder")
    public Result createOrder(@RequestBody Order order) {
        Order resOrder = ordersService.addOrder(order);
        return Result.success(resOrder);
    }

    @RequestMapping("/getOrderList")
    public Result getOrderList(int id) {
        List<Order> list = ordersService.getOrderList(id);
        return Result.success(list);
    }

    //用户手动确认订单已完成
    @RequestMapping("/finishOrder")
    public Result finishOrder(String id) {
        ordersService.finishOrder(id);
        return Result.success("成功");
    }

    //分页查询
    @RequestMapping("/getOrderListByPage")
    @CrossOrigin
    public Result getOrderListByPage(Integer pageNum, Integer pageSize) {
        List<Order> orders = ordersService.getOrderListByPage(pageNum, pageSize);
        return Result.success(orders);
    }

    @RequestMapping("/getAllOrderCount")
    @CrossOrigin
    public Result getAllOrderCount() {
        int count = ordersService.getAllOrderCount();
        return Result.success(count);
    }

    @RequestMapping("/refundOrderSubmit")
    public Result refundOrderSubmit(@RequestBody RefundOrder refundOrder) {
        ordersService.refundOrderSubmit(refundOrder);
        return Result.success("成功");
    }

    @GetMapping("/getAllRefundOrders")
    @CrossOrigin
    public Result getAllRefundOrders() {
        List<RefundOrder> refundOrders = ordersService.getAllRefundOrders();
        return Result.success(refundOrders);
    }

    @GetMapping("/getAppRefundOrders")
    public Result getAppRefundOrders(int id) {
        List<Order> refundOrders = ordersService.getAppRefundOrders(id);
        return Result.success(refundOrders);
    }

    @RequestMapping("/confirmRefund")
    @CrossOrigin
    public Result confirmRefund(@RequestBody RefundOrder refundOrder) {
        ordersService.confirmOrder(refundOrder);
        return Result.success("成功");
    }
}
